//
//  GroupTableController.m
//  DaBaiSite
//
//  Created by Mac-Mini-KingVision on 16/1/7.
//  Copyright © 2016年 admin. All rights reserved.
//

#import "GroupTableController.h"

@implementation GroupTableController

-(id)initWithAutoLayout
{
    self = [super init];
    if (self) {
        self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        self.tableView.dataSource = self;
        self.tableView.delegate = self;
        [self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
        
    }
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.listArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.classForCell) forIndexPath:indexPath];
    cell.delegate = self;
    id data = [self.listArray objectAtIndex:indexPath.section];
    [cell setValue:data];
    [cell setValue:data andIndexPath:indexPath];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    id data = [self.listArray objectAtIndex:indexPath.section];
    return [self.classForCell heightForTableViewCell:data];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectedCell:dataSrc:row:)]) {
        id data = [self.listArray objectAtIndex:indexPath.section];
        [self.delegate didSelectedCell:self dataSrc:data row:indexPath.section];                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
    }
}


@end
